package com.yyk.yykywd.util;

import android.net.Uri;

import com.yyk.yykywd.KotlinConstantKt;

import org.devio.takephoto.app.TakePhoto;
import org.devio.takephoto.compress.CompressConfig;
import org.devio.takephoto.model.CropOptions;

/**
 * 文件描述：
 * Created by guo on 2019/5/29.
 */
public class TakePhotoHelper {
    public static CropOptions configTakePhoto(TakePhoto takePhoto, boolean isEqualProportionCrop) {
        //设置压缩规则
        takePhoto.onEnableCompress(new CompressConfig.Builder()
                .setMaxSize(500 * 1024)
                .setMaxPixel(6000)
                .enablePixelCompress(true)
                .enableQualityCompress(true)
                .create(), true);
        //返回裁剪配置
        if (isEqualProportionCrop) {
            return new CropOptions.Builder().setAspectX(1).setAspectY(1).setWithOwnCrop(false).create();
        } else {
            return new CropOptions.Builder().setWithOwnCrop(false).create();
        }
    }

    public static void takePhotoOperation(TakePhoto takePhoto, String type, int limit) {
        Uri uri = FileUtils.getUri();
        CropOptions cropOptions = configTakePhoto(takePhoto, false);
        if (type.equals(KotlinConstantKt.CAMERA)) {
            //拍照
            takePhoto.onPickFromCaptureWithCrop(uri, cropOptions);
        } else {
            //相册
            if (limit == 1) {//limit为1说明是单选
                takePhoto.onPickFromGalleryWithCrop(uri, cropOptions);
            } else {
                takePhoto.onPickMultipleWithCrop(limit, cropOptions);
            }
        }
    }
}
